package com.tj.test.sys.controller;

import com.tj.test.sys.po.Register;
import com.tj.test.sys.service.impl.RegisterService;
import com.tj.test.sys.tool.ResponseMessage;
import com.tj.test.sys.tool.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping("/register")
@Controller
@Api(tags = "register")
@CrossOrigin
public class RegisterController {
    @Autowired
    private RegisterService service;

    @ApiOperation("根据id查询登录信息")
    @RequestMapping(value = "/selectById", method = RequestMethod.GET)
    @ResponseBody
    public ResponseMessage selectById(int personid) {
        Map<String, List<Register>> map = new HashMap<>();
        List<Register> list = service.selectById(personid);
        if (!list.isEmpty()) {
            map.put("reg", list);
            return Result.success("查询成功", map);
        }
        return Result.error("查询信息失败");
    }


    @ApiOperation("插入登录信息")
    @RequestMapping(value = "/insert", method = RequestMethod.GET)
    @ResponseBody
    public ResponseMessage insertRegister(Register register) {
        if (service.insertRegister(register)==1) {
            return Result.success("插入成功", service.insertRegister(register));
        }
        return Result.error("插入失败");
    }
}
